import redis

class RdeisCon:
    def __init__(self):
        self.conn = redis.Redis(host='127.0.0.1',port=6379)

    def set_str(self,key,value,time=0):
        #判断是否有过期时间
        if time:
            self.conn.setex(key,time,value)#以秒为单位
        else:
            self.conn.set(key,value)
    #获取字符串
    def get_str(self,key):
        #根据Key找Value
        value = self.conn.get(key)
        if value:
            value = str(value,encoding='utf8')
        return value

    def del_str(self,key):
        self.conn.delete(key)


r = RdeisCon()

# r.set_str('188','88',10)
print(r.get_str('188'))










